<template>
  <view class="container">
    <z-paging-swiper>
      <view slot="top">
        <u-navbar height="50" title="视频管理" title-size="36" title-color="#333"></u-navbar>
        <view class="tabsView">
          <u-tabs-swiper
            ref="uTabs"
            :list="tabsList"
            :current="current"
            @change="tabsChange"
            :is-scroll="false"
            :show-bar="false"
            active-color="#0F76BC"
            swiper-width="750"
          >
          </u-tabs-swiper>
        </view>
        <u-gap height="20" bg-color="#F0F1F2"></u-gap>
      </view>
      <swiper
        class="swiperView"
        :current="scurrent"
        @transition="transition"
        @animationfinish="animationfinish"
      >
        <swiper-item v-for="(item2, indexx) in tabsList" :key="indexx" class="swiperItem">
          <z-paging
            ref="paging"
            v-model="itemList[indexx]"
            @query="queryList"
            :fixed="true"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view class="itemView" v-for="(item, index1) in itemList[indexx]" :key="index1">
                <view class="order-top">
                  <view class="top-lef">
                    <view
                      v-if="item.status == 1"
                      style="color: #0f76bc; border: solid 2rpx #0f76bc"
                      class="order-top-tip"
                    >
                      售卖中
                    </view>
                    <view
                      v-else-if="item.status == 0"
                      style="color: #ffac0e; border: solid 2rpx #ffac0e"
                      class="order-top-tip"
                    >
                      审核中
                    </view>
                    <view
                      v-else-if="item.status == 2"
                      style="color: #999999; border: solid 2rpx #999999"
                      class="order-top-tip"
                    >
                      已下架
                    </view>
                    <text
                      @click="onMore(index1)"
                      style="margin-top: -30rpx; margin-left: 25rpx; font-size: 55rpx"
                      >...</text
                    >
                  </view>
                  <view class="top-rig">
                    <!-- <view class="total">
											已售*件 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 收入*
										</view> -->
                  </view>

                  <view v-if="moreIndex === index1" class="more">
                    <view v-if="item.status == 2" @click="up(item)" class="more-item">
                      上架视频
                    </view>
                    <view v-if="item.status == 1" @click="down(item)" class="more-item">
                      下架视频
                    </view>
                    <view @click="delVideo(item)" class="more-item"> 删除视频 </view>
                  </view>
                </view>

                <view class="goods-video">
                  <view class="orde-lef">
                    <u-icon style="border-radius: 10rpx" :name="item.coverUrl" size="200"></u-icon>
                  </view>
                  <view class="orde-rig" v-if="item.spuList && item.spuList.length > 0">
                    <view class="goods-item">
                      <view class="" style="text-align: end; border-radius: 10rpx">
                        <u-icon
                          style=""
                          class="goods-img"
                          :name="item.spuList[0].picUrl"
                          size="140"
                        ></u-icon>
                      </view>

                      <view class="goods-desc">
                        <view class="goods-title">
                          {{ item.spuList[0].name }}
                        </view>
                        <view class="goods-price">
                          ¥{{ (item.spuList[0].price * 0.01).toFixed(2) }}
                        </view>
                      </view>
                    </view>
                    <view class="" style="margin-bottom: 15rpx"> 关联商品 </view>
                  </view>
                  <view v-else class="orde-rig">
                    <view class="" style="margin-bottom: 15rpx"> 未关联商品 </view>
                  </view>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
      </swiper>
    </z-paging-swiper>

    <view class="handle-btn-area">
      <view class="handle-btn" @click="routeTo('/other_center/mer-video-push/mer-video-push')">
        <u-icon name="/static/img/fbxx.png" size="55rpx"></u-icon>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      imgStyle: {
        width: '12rem'
      },
      moreIndex: '',
      current: 0,
      scurrent: 0,
      tabsList: [
        {
          name: '全部',
          status: ''
        },
        {
          name: '审核中',
          status: 0
        },
        {
          name: '售卖中',
          status: 1
        },
        {
          name: '已下架',
          status: 2
        }
      ],
      itemList: [[], [], [], []],
      order_id: ''
    }
  },
  onLoad(res) {},
  onShow() {
    this.queryList()
  },
  methods: {
    tabsChange(index) {
      this.scurrent = index
    },
    transition(e) {
      let dx = e.detail.dx
      this.$refs.uTabs.setDx(dx)
    },
    animationfinish(e) {
      this.current = e.detail.current
      this.scurrent = e.detail.current
      this.$refs.uTabs.setFinishCurrent(e.detail.current)
      if (this.itemList[this.current].length == 0) {
        this.queryList()
      }
    },
    queryList(pageNo = 1, pageSize = 10) {
      this.$u
        .get('/app-api/vlog/info/my-page', {
          pageNo,
          pageSize,
          status: this.tabsList[this.scurrent].status
        })
        .then((res) => {
          this.$refs.paging[this.scurrent].complete(res.data.list)
        })
    },

    onOrderCancel(item) {
      let self = this
      uni.dialog.confirm('温馨提示', '确定要取消订单吗？', () => {
        self.$u.api.setOrderCancel(item.id).then((res) => {
          self.$u.toast('取消成功')
          setTimeout(function () {
            self.onOrderLoad(self.current, null, true)
          }, 500)
        })
      })
    },

    onOrderPayment(item) {
      let self = this
      this.$utils.route({
        url: '/goods/payment/payment',
        params: {
          order_id: item.id,
          money: item.pay_price,
          total_weight: item.total_weight,
          delivery_price: item.delivery_price
        }
      })
    },
    onOrderConfrim(item) {
      let self = this
      uni.dialog.confirm('温馨提示', '该订单确认收货吗？', () => {
        self.$u.api.setOrderConfirm(item.id).then((res) => {
          self.$u.toast('收货成功')
          setTimeout(function () {
            self.onOrderLoad(self.current, null, true)
          }, 500)
        })
      })
    },
    onResellPush(item) {
      this.$utils.route({
        url: '/goods/resell-push/resell-push',
        params: {
          id: item.id
        }
      })
    },
    onPushComment(item) {
      this.$utils.route({
        url: '/other/push-comment/push-comment',
        params: {
          id: item.id
        }
      })
    },
    onOrderDetail(item) {
      this.$utils.route({
        url: '/other_center/mer-order-details/mer-order-details',
        params: {
          id: item.id
        }
      })
    },
    onMore(e) {
      if (e === this.moreIndex) {
        this.moreIndex = ''
        return
      }
      this.moreIndex = e
    },
    routeTo(url) {
      uni.navigateTo({
        url
      })
    },
    up(e) {
      this.moreIndex = ''
      uni.dialog.confirm('温馨提示', '是否上架视频？', () => {
        this.$u.put('/app-api/vlog/info/shelve?id=' + e.id).then((res) => {
          this.queryList()
          //this.$refs.paging[this.scurrent].reload()
        })
      })
    },
    down(e) {
      this.moreIndex = ''
      uni.dialog.confirm('温馨提示', '是否下架视频？', () => {
        this.$u.put('/app-api/vlog/info/unshelve?id=' + e.id).then((res) => {
          this.queryList()
          //this.$refs.paging[this.scurrent].reload()
        })
      })
    },
    delVideo(e) {
      this.moreIndex = ''
      uni.dialog.confirm('温馨提示', '是否删除视频？', () => {
        this.$u.delete('/app-api/vlog/info/delete?id=' + e.id).then((res) => {
          this.queryList()
          //this.$refs.paging[this.scurrent].reload()
        })
      })
    }
  }
}
</script>

<style>
page {
  height: 100%;
  background: #f0f1f2;
}

.tabsView {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  height: 90rpx;
}

.goodsItemView {
  display: flex;
  flex-direction: column;
}

.itemView {
  background-color: #ffffff;
  margin-bottom: 1rem;
  border-radius: 6px;
  padding: 20rpx;
}

.order-lef {
  flex: 3;
}
.order-rig {
  flex: 7;
}
.order-top {
  display: flex;
  padding: 15rpx 0;
  font-size: 30rpx;
  position: relative;
}

.more {
  position: absolute;
  top: 85rpx;
  left: -5rpx;
  width: 160rpx;
  background-color: #fff;
  z-index: 999;
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.12),
    0 0 6px rgba(0, 0, 0, 0.04);
}
.more-item {
  padding: 20rpx;
  height: 80rpx;
  border-bottom: #ededed solid 2rpx;
}

.order-top-tip {
  display: inline-block;
  color: #999999;
  padding: 8rpx 10rpx;
  font-size: 26rpx;
  border-radius: 10rpx;
}
.top-lef {
  flex: 3;
  display: flex;
  align-items: center;
}
.top-rig {
  flex: 7;
  font-size: 30rpx;
  color: #666666;
}

.goods-desc {
  margin-left: 15rpx;
  line-height: 60rpx;
}

.total {
  background-color: #f2f2f2;
  padding: 12rpx 15rpx;
  border-radius: 10rpx;
}

.goods-video {
  display: flex;
}

.orde-lef {
  flex: 3;
}
.orde-rig {
  flex: 7;
  display: flex;
  flex-direction: column-reverse;
}

.goods-item {
  display: flex;
}

.goods-img {
  border-radius: 20rpx;
}

.orde-riget {
  width: 100%;
  margin-left: 10rpx;
  line-height: 55rpx;
  font-size: 26rpx;
}

.goods-speci {
  position: relative;
}

.goods-num {
  position: absolute;
  top: 0;
  right: 0;
  color: #999999;
}

.goods-price {
  font-size: 30rpx;
  color: #f54831;
}

.price-total {
  padding: 20rpx 0;
  border-top: #ededed solid 2rpx;
  border-bottom: #ededed solid 2rpx;
  text-align: right;
  font-size: 28rpx;
  margin: 15rpx 0;
}

.btn-group {
  display: flex;
  flex-direction: row-reverse;
}

.btn {
  display: inline-block;
  padding: 15rpx 20rpx;
  border-radius: 35rpx;
  font-size: 28rpx;
  margin-left: 15rpx;
}

.hollow-btn {
  color: #666666;
  border: #e6e6e6 solid 2rpx;
}

.solid-btn {
  background-color: #0f76bc;
  color: #fff;
}

.handle-btn-area {
  position: fixed;
  right: 20rpx;
  bottom: 150rpx;
  z-index: 9999;
  display: flex;
  flex-direction: column;
}

.handle-btn {
  margin-bottom: 20rpx;
  width: 120rpx;
  height: 120rpx;
  background-color: #0f76bc;
  border-radius: 100rpx;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
